package com.heima.exam.p3;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

public class Filter {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("com.heima.exam.p3.Student");
        Constructor<?> constructor = aClass.getConstructor(String.class, int.class);
        Student stu1 = (Student) constructor.newInstance("xiao1", 16);
        Student stu2 = (Student) constructor.newInstance("xiao2", 17);
        Student stu3 = (Student) constructor.newInstance("xiao2", 17);
        Student stu4 = (Student) constructor.newInstance("xiao4", 20);
        Student stu5 = (Student) constructor.newInstance("xiao5", 20);
        HashSet<Student> hs = new HashSet<>();
        Collections.addAll(hs, stu1, stu2, stu3, stu4, stu5);
        List<Student> collect = hs.stream().filter(student -> student.age < 18).collect(Collectors.toList());
        for (Student student : collect) {
            System.out.println(student);
        }

    }
}
